<template>
  <div class="qcRecoedTaskPool">
    <div class="publicSearch">
      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button
            @click="getqcRecoedTaskPoolData"
            size="mini"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh"
            >重置</el-button
          >
        </el-button-group>
        <div>
          <span>入库任务号</span>
          <el-input
            v-model="searchData.asnMasterCode"
            size="mini"
            placeholder="入库任务号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>收货单号</span>
          <el-input
            v-model="searchData.acceptRecordCode"
            size="mini"
            placeholder="收货单号"
            clearable
          ></el-input>
        </div>
        <div>
          <span>批次编码查询</span>
          <el-input
            v-model="searchData.batchName"
            size="mini"
            placeholder="批次编码"
            clearable
          ></el-input>
        </div>
        <div>
          <span>物料编码查询</span>
          <el-input
            v-model="searchData.itemCode"
            size="mini"
            placeholder="物料编码"
            clearable
          ></el-input>
        </div>
        <div>
          <span>物料名称查询</span>
          <el-input
            v-model="searchData.itemName"
            size="mini"
            placeholder="物料名称"
            clearable
          ></el-input>
        </div>
      </div>
    </div>
    <!--检查结果 -->
    <el-dialog
      title="质检结果"
      :visible.sync="checkQc"
      :close-on-click-modal="false"
      width="20%"
      center
    >
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item label="待检数量" prop="qty" :label-width="formLabelWidth">
          <span>{{ form.qty }}</span>
        </el-form-item>
        <el-form-item
          label="合格数量"
          prop="qualifiedQuantity"
          :label-width="formLabelWidth"
        >
          <el-input
            type="number"
            v-model="form.qualifiedQuantity"
            placeholder="合格数量"
            maxlength="20"
            style="width: 90%"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="不合格数量"
          prop="fiedQuantity"
          :label-width="formLabelWidth"
        >
          <el-input
            type="number"
            v-model="form.fiedQuantity"
            placeholder="不合格数量"
            maxlength="20"
            style="width: 90%"
          ></el-input>
        </el-form-item>
         <el-form-item label="备注" prop="memo"  :label-width="formLabelWidth">
          <el-input v-model="form.memo" type="textarea"  placeholder="请输入备注"></el-input>
        </el-form-item>
        <!-- <el-form-item label="让步数量" prop="concessionQuantity" :label-width="formLabelWidth">
          <el-input
            type="number"
            v-model="form.concessionQuantity"
            placeholder="让步数量"
            maxlength="20"
            style="width: 90%;"
          ></el-input>
        </el-form-item> -->

        <!-- <el-radio-group v-model="form.qcResult">
          <el-radio :label="0">不合格</el-radio>
          <el-radio :label="1">合格</el-radio>
          <el-radio :label="2">让步</el-radio>
        </el-radio-group> -->
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="checkQc = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="ChangeQc" size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <div class="tableBox">
      <el-table
        v-loading="loading.masterTable"
        highlight-current-row
        :row-class-name="tableRowClassName"
        :data="qcRecoedTaskPools"
        style="width: 100%"
        :row-style="MyStyle"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          fixed="left"
          type="index"
          width="100"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="asnBillNo"
          label="入库任务号"
          width="180"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="acceptRecordCode"
          label="收货单号"
          min-width="120"
        >
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="test(scope.row.acceptRecordCode, 'item')"
            >
              {{ scope.row.acceptRecordCode }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="itemCode"
          label="物料编码"
          min-width="120"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="itemName"
          label="物料名称"
          min-width="100"
        >
          <template slot-scope="scope">
            <span class="textBtn" @click="test(scope.row.itemName, 'item')">
              {{ scope.row.itemName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="batchName"
          label="批次号"
          min-width="120"
        ></el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="qty"
          label="待检数量"
          min-width="100"
        ></el-table-column>
        <!-- <el-table-column
          sortable
          show-overflow-tooltip
          prop="createTime"
          label="创建时间"
          min-width="150"
        ></el-table-column>-->
        <el-table-column fixed="right" label="操作" min-width="80">
          <template slot-scope="scope">
            <el-button
              @click="showNewModal(scope.row)"
              type="primary"
              size="small"
              :disabled="scope.row.state === 2"
              >&nbsp;质检结果</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="text-align: right"
        class="pagination-bottom"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        :page-sizes="[10, 20, 30, 50]"
        :current-page.sync="searchData.pageNum"
        :page-size="searchData.pageSize"
        layout="sizes,total, prev, pager, next"
        :total="searchData.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "qcRecoedTaskPool",
  data() {
    // 校验规则
    return {
      isMoreSearch: false,
      loading: {
        masterTable: true
      },
      // 用作查询的数据
      searchData: {
        // 仓库编码 获得当前仓库的编码
        wareId: PF.getLocal("wareId", "number"),
        // 物料编码查询
        itemCode: "",
        itemName:"",
        acceptRecordCode:"",
        pageNum: 1,
        pageSize: 10,
        total: null,
        // 批次号查询
        batchName: "",
        asnMasterCode: ""
      },
      searchStates: [
        {
          value: "enable",
          label: "启用"
        },
        {
          value: "disable",
          label: "禁用"
        }
      ],
      rules: {
        qualifiedQuantity: [
          { required: true, message: "请输入合格数量", trigger: "blur" }
        ],
        fiedQuantity: [
          { required: true, message: "请输入不合格数量", trigger: "blur" }
        ],
       
        // concessionQuantity: [
        //   { required: true, message: "请输入让步数量", trigger: "blur" }
        // ]
      },
      form: {
        // 仓库编码 获得当前仓库的编码
        wareId: PF.getLocal("wareId", "number"),
        // 收货单编码
        billCode: "",
        // 合格数量
        qualifiedQuantity: "",
        //备注
        memo : "",
        // 不合格数量
        fiedQuantity: "",
        //  让步数量
        concessionQuantity: "0",
        // 质检结果--默认是合格的
        qcResult: 1,
        qty: ""
      },
      currentAcceptRecordCode: "",
      //存放装箱单数据的数组
      qcRecoedTaskPools: [],
      // 显示检测弹框
      checkQc: false,
      MyStyle: { height: "50px" },
      formLabelWidth: "120px",
      rowData: {
        //
      },
      filterText: "",
      defaultProps: {
        children: "children",
        label: "name"
      },
      roleRowInfo: {
        //
      },
      roleForm: {
        //
      },
      roleRules: {
        //
      },
      tableRowClassName({ row, rowIndex }) {
        if (row.accountStatus === "disable") {
          return "disable-row";
        } else if (row.accountStatus === "enable") {
          return "enable-row";
        }
        return "";
      }
    };
  },
  computed: {},
  watch: {
    //
  },
  methods: {
    //分页设置每页的条数
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getqcRecoedTaskPoolData();
    },
    //分页设置从第几条开始
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getqcRecoedTaskPoolData();
    },
    // 清空查询条件
    clearSearchData() {
      this.searchData.batchName = "";
      this.searchData.itemCode = "";
      this.searchData.asnMasterCode = "";
      this.searchData.itemName = "";
      this.searchData.acceptRecordCode = "";
    },
    //根据筛选条件查询数据
    getqcRecoedTaskPoolData() {
      let that = this;
      that.loading.masterTable = true;
      let searchData = JSON.parse(JSON.stringify(this.searchData));
      IOT.getServerData("/qc/task/list", "get", searchData, ret => {
        that.loading.masterTable = false;
        if (ret.code === 200) {
          // rows就是返回的数据
          this.qcRecoedTaskPools = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    // 打开弹框
    showNewModal(row) {
      if (row == null) {
        this.$message({
          message: "请选择一条数据",
          type: "warning"
        });
      } else {
        this.checkQc = true;
        // 收货编号
        this.form.billCode = row.acceptRecordCode;
        this.form.qty = row.qty;
      }
    },
    // 提交质检结果
    ChangeQc() {
       if(this.form.fiedQuantity*1 < 0 || this.form.qualifiedQuantity*1 < 0 ){
           IOT.tips( "不能输入负数请重新输入!", "error");
           return;
       }
      if((this.form.fiedQuantity*1 + this.form.qualifiedQuantity*1) > this.form.qty*1){
           IOT.tips( "质检数量大于待检数量请重新填写!", "error");
           return;
      }
       if(this.form.fiedQuantity*1 === 0 && this.form.qualifiedQuantity*1 ===  0 ){
           IOT.tips( "请输入合格数量或者不合格数量，不能都输入0!", "error");
           return;
       }
      // 关闭弹框
      this.checkQc = false;
      var params = {
        billCode: "",
        qcRecordList: [{
            qualifiedQuantity: this.form.qualifiedQuantity,
            fiedQuantity : this.form.fiedQuantity,
            acceptRecordCode : this.form.billCode ,
            memo : this.form.memo,

          }
        ]
      }
      // 后台保存质检结果
      IOT.getServerData("/qc/records/submit", "post", params, ret => {
        if (ret.code === 200) {
          IOT.tips("保存成功！", "success");
          this.getqcRecoedTaskPoolData();
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    }
    // // 进行删除
    // isDelete(id) {
    //   this.$confirm("确认删除？")
    //     .then(_ => {
    //       this.delete(id);
    //     })
    //     .catch(_ => {});
    // },
    // // 根据主键id删除
    // delete(id) {
    //   let that = this;
    //   IOT.showOverlay("删除中，请稍等...");
    //   IOT.getServerData("/qcRecoedTaskPool/deleteById", "get", { id: id }, ret => {
    //     IOT.hideOverlay();
    //     if (ret.code === 200) {
    //       IOT.tips("删除成功！", "success", 1000, () => {
    //         that.getqcRecoedTaskPoolData();
    //       });
    //     } else {
    //       IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
    //     }
    //   });
    // },
  },
  // 页面加载时刷新
  created() {
    this.searchData.pageNum = 1;
    this.searchData.pageSize = 10;
    //请求数据
    this.getqcRecoedTaskPoolData();
  }
};
</script>

<style scoped lang="less">
.qcRecoedTaskPool {
}
</style>
